﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace PRE
{
    using DAL;
    using DAL.Entities;
    using System.Data.Entity;

    public partial class FrmDemo : Form
    {
        public FrmDemo()
        {
            InitializeComponent();
        }

        private void FrmDemo_Load(object sender, EventArgs e)
        {
            Database.SetInitializer<MyContext>(new DropCreateDatabaseIfModelChanges<MyContext>());

            using (var db = new MyContext())
            {
                var x = new Group() { Name = "Toan" };
                db.Groups.Add(x);

                var y = new Kind() { Name = "", GroupId = 1, ChairMax = 10, ChairMin = 1, Descript = "?", LengthMax = 1, LengthMin = 0, Money1 = 1, Money2 = 1, WeightMax = 10, WeightMin = 0 };
                db.Kinds.Add(y);
                int recordsAffected = db.SaveChanges();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            using (var db = new MyContext())
            {
                var allFoods = from p in db.Groups
                               orderby p.Name
                               select new
                               {
                                   p.Id,
                                   p.Name
                               };

                dataGridView1.DataSource = DAL.MyContext.Linq2Table(allFoods, "Tmp");
            }
        }
    }
}